package myky.com.doctorapp.ui

import android.os.Bundle
import android.view.View
import android.widget.ExpandableListView


import com.gyf.barlibrary.ImmersionBar
import kotlinx.android.synthetic.main.activity_remote_doctor_list.*
import kotlinx.android.synthetic.main.public_common_title.*
import myky.com.doctorapp.R
import myky.com.doctorapp.adapter.ExpandListAdapter
import myky.com.doctorapp.entity.RemoteListEntity
import myky.com.doctorapp.base.BaseActivity
import myky.com.doctorapp.contract.RemoteDoctorListContract
import myky.com.doctorapp.presenter.RemoteDoctorListPresenter
import myky.com.doctorapp.utils.Constants

/**
 * Description:
 * @author wuyangwuyang
 * Created by 2019/1/9 on 9:59
 */
class RemoteDoctorListActivity:BaseActivity<RemoteDoctorListPresenter, RemoteListEntity.PayLoadBean>(),RemoteDoctorListContract.View ,ExpandableListView.OnChildClickListener,View.OnClickListener{



    private lateinit var expandableListAdapter: ExpandListAdapter
    private  lateinit var  hospitalListEntity: ArrayList<RemoteListEntity.PayLoadBean.HospitalListBean>
    override fun getPresenter()=RemoteDoctorListPresenter()

    override fun reloadActivity() {
    }

    override fun injectTarget(): View =findViewById(R.id.remote_lin)

    override fun initData() {

        hospitalListEntity= ArrayList()
        expandableListAdapter=ExpandListAdapter(this, hospitalListEntity)
        remote_expandable.setGroupIndicator(null)//不显示自带的下拉指示器
        remote_expandable.setOnChildClickListener(this)
        backLayout.setOnClickListener(this)
        remote_expandable.setAdapter(expandableListAdapter)
        mPresenter.findRemoteDoctorList()

    }

    override fun initView() {
        conmonTitleTextView.text= getText(R.string.RemoteDoctorList_title)
        ImmersionBar.with(this)
                .statusBarColor(R.color.colorPrimary)
                .titleBar(R.id.commonTitleLayout)  //使用该属性必须指定状态栏的颜色，不然状态栏透明，很难看
                .init()
    }

    override fun getContenView(): Int = R.layout.activity_remote_doctor_list

    override fun showDataSuccess(datas: RemoteListEntity.PayLoadBean?) {
    }

    override fun showRemoteDoctorList(doctorListEntity: RemoteListEntity.PayLoadBean) {

        var hospitalList = doctorListEntity.hospitalList
        hospitalListEntity.addAll(hospitalList)
        expandableListAdapter.notifyDataSetChanged()
        remote_expandable.expandGroup(0)
    }

    override fun onChildClick(p0: ExpandableListView?, p1: View?, p2: Int, p3: Int, p4: Long): Boolean {

        var doctorsBean = hospitalListEntity[p2].doctors[p3]
        val bundle = Bundle()
        bundle.putInt(Constants.DOCTORID, doctorsBean.doctorid)
        startActivity(DoctorDetailsActivity::class.java, bundle)

        return false
    }


    override fun onClick(view: View?) {

        when(view?.id){

            R.id.backLayout-> finish()


        }
    }
}